/*
 * @Author: HZK
 * @Date: 2020-09-25 13:07:53
 * @LastEditTime: 2020-12-29 11:19:37
 * @LastEditors: hanfengmi
 * @Description: 菜单渲染
 *
 * @params:
 * list // 菜单列表
 * * type 跳转类型 url,跳转外部链接；link,内部路由跳转
 * * url: 跳转链接
 * * title: 名称
 */
import React, { PureComponent } from 'react'
import router from 'umi/router'
import withRouter from 'umi/withRouter'
import styles from './index.less'
@withRouter
class Index extends PureComponent {
  JumpTo=(item)=>{
    if(item.type === 'url') {
      window.open(item.url)
    }else {
      router.push(item.url)
    }
  }
  render() {
    const { list, location: { pathname } } = this.props
    return(
      <div className={styles.MenuListWrap}>
        {list.map(e => <div className={`${styles.MenuItem} ${pathname === e.url && styles.Active}`} onClick={()=> this.JumpTo(e)} key={ e.url }>{ e.name }</div>)}
      </div>
    )
  }
}

export default Index